package com.boe.common.jdbc;

import cn.hutool.extra.spring.SpringUtil;
import com.boe.common.util.ClassUtil;
import com.google.common.base.Strings;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class ExistsSqlSourceConfigCondition implements Condition {

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        if (Strings.isNullOrEmpty(SpringUtil.getProperty("spring.datasource.url"))) {
            return false;
        }

        return ClassUtil.existsClass("org.mariadb.jdbc.Driver") ||
                ClassUtil.existsClass("com.mysql.cj.jdbc.Driver") ||
                ClassUtil.existsClass("com.microsoft.sqlserver.jdbc.SQLServerDriver") ||
                ClassUtil.existsClass("org.sqlite.JDBC") ||
                ClassUtil.existsClass("org.postgresql.Driver") ||
                ClassUtil.existsClass("oracle.jdbc.driver.OracleDriver");
    }
}
